﻿//-----------------------------------------------------------------------
// <copyright file="JustifyRuleViolationSuppressionsConfiguration.cs">
//     Copyright (c) Nicole Calinoiu. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

using Bordecal.FxCop.Sdk;

namespace Bordecal.FxCop.Rules.Usage.Configuration
{
	/// <summary>
	/// Configuration for the <see cref="JustifyRuleViolationSuppressions"/> rule.
	/// </summary>
	public sealed class JustifyRuleViolationSuppressionsConfiguration : RuleConfiguration
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="JustifyRuleViolationSuppressionsConfiguration"/> class.
		/// </summary>
		public JustifyRuleViolationSuppressionsConfiguration()
		{
			this.MinimumJustificationLength = 10;

			this.InitializeSettings();
		}

		/// <summary>
		/// Gets the minimum acceptable justification length (after trimming).
		/// </summary>
		internal int MinimumJustificationLength { get; private set; }

		/// <summary>
		/// Copies settings from instance properties to a string dictionary.
		/// </summary>
		/// <param name="dictionary">The target settings <see cref="Dictionary{String, String}"/>.</param>
		protected override void DoCopySettings(Dictionary<string, string> dictionary)
		{
			if (dictionary == null)
			{
				throw new ArgumentNullException("dictionary");
			}

			dictionary.Add("MinimumJustificationLength", this.MinimumJustificationLength.ToString(CultureInfo.InvariantCulture));
		}

		/// <summary>
		/// Sets configuration property values from the contents of a string dictionary.
		/// </summary>
		/// <param name="dictionary">The source <see cref="Dictionary{String, String}"/>.</param>
		protected override void DoLoadFromDictionary(Dictionary<string, string> dictionary)
		{
			if (dictionary == null)
			{
				throw new ArgumentNullException("dictionary");
			}

			this.MinimumJustificationLength = int.Parse(dictionary["MinimumJustificationLength"], NumberStyles.None, CultureInfo.InvariantCulture);
		}
	}
}